package cn.harry.cabinet.repository

import androidx.lifecycle.MutableLiveData

/**
 * MVVM架构的基础Repository类
 * 用于管理数据源和数据操作
 */
open class BaseRepository {
    
    // 创建一个结果包装类
    protected class Result<T> {
        var data: T? = null
        var error: String? = null
        var isLoading = false
        
        companion object {
            fun <T> success(data: T): Result<T> {
                val result = Result<T>()
                result.data = data
                return result
            }
            
            fun <T> error(message: String): Result<T> {
                val result = Result<T>()
                result.error = message
                return result
            }
            
            fun <T> loading(): Result<T> {
                val result = Result<T>()
                result.isLoading = true
                return result
            }
        }
    }
    
    // 创建一个LiveData结果
    protected fun <T> liveDataResult(): MutableLiveData<Result<T>> {
        return MutableLiveData()
    }
}